<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*, java.util.*" %>
<%
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    String url = "jdbc:mysql://localhost:3306/books?serverTimezone=Asia/Shanghai";
    String user = "root";
    String password = "123456";
    String currentTime = "无法获取时间";
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        // Establish connection
        conn = DriverManager.getConnection(url, user, password);
        stmt = conn.createStatement();
        String sql = "SELECT current_time FROM CurrentTimeView"; // 查询视图
        rs = stmt.executeQuery(sql);

        if (rs.next()) {
            currentTime = rs.getString("current_time");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            // Close the resources
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    out.print(currentTime);
%>
